IF EXISTS(SELECT * FROM sysobjects WHERE name = 'generarCodigoSondaje' AND type = 'P')
BEGIN
	DROP PROCEDURE generarCodigoSondaje
END
GO
CREATE PROCEDURE generarCodigoSondaje

AS
/*********************************************************************
	Resumen: Genera codigo de Sondaje
	Parametros:
**********************************************************************/		

BEGIN

	DECLARE @CodigoSondaje INT
	SELECT @CodigoSondaje = CONVERT(INT, ISNULL(MAX(t1.CodigoSondaje), 0)) + 1 FROM Sondaje t1
	
	SELECT @CodigoSondaje AS CodigoSondaje
END